package lab.loader;

import java.io.File;
import java.util.Scanner;

import lab.loader.bean.Animal;

import cn.flant.util.ClassUtil;

public class TestLoader {

	public static void main(String[] args) {
		TestLoader test = new TestLoader();
		test.test_2();
	}

	public void test_2() {
		String className = "cn.flant.loader.bean.Cat";
		Scanner scanner = new Scanner(System.in);
		String line = null;
		while ((line = scanner.nextLine()) != null) {
			line = line.trim().toLowerCase();
			if ("load".equals(line)) {
				ClassUtil.addExtLibPath(new File("f:/lib/"));
				Class<?> clazz = ClassUtil.loadClass(className);
				if (clazz != null) {
					Animal animal = (Animal) ClassUtil.newInstance(clazz);
					animal.run();
				} else {
					System.out.println("not found " + className);
				}
			}
		}

	}

	public void test_1() {
		Scanner scanner = new Scanner(System.in);
		String className = null;
		while (true) {
			className = scanner.nextLine();
			if (className == null || className.trim().length() == 0) {
				continue;
			}
			className = "cn.flant.loader.bean." + className;
			Class<?> clazz = ClassUtil.loadClass(new File("f:/bin/Animals.jar"), className);
			if (clazz != null) {
				Animal animal = (Animal) ClassUtil.newInstance(clazz);
				animal.run();
			} else {
				System.out.println("not found " + className);
			}
		}
	}
}
